package com.example.order.controller;
import com.example.common.Dto;
import com.example.order.service.OrderService;
import com.example.vo.OrderVo;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by LENOVO on 2018/9/23.
 */
@RestController
@RequestMapping("/api")
public class OrderController {

    @Resource
    private OrderService orderService;

    @RequestMapping("/queryOrderList")
    @ResponseBody
    public Dto<List<OrderVo>> queryOrderList(HttpServletResponse response, HttpServletRequest request){
        response.setHeader("Access-Control-Allow-Origin", "*");
        Dto<List<OrderVo>> listDto=null;
        try {
            listDto=orderService.queryOrderList(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listDto;
    }
    /***
     * 30分钟执行一次 刷新订单的状态 不对外公布
     */
    @Scheduled(cron = "0/10 * * * * ?")
    public void flushCancelOrderStatus() {
        try {
            orderService.cancelOrderStatus();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
